// 导入request库
import request from "../utils/request";

// 服务器地址
import host_config from "./server";
const HOST_URL = host_config.url;

// 管理员部分
// 注册接口
export const registerAPI = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/user/register`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};
// 登录接口
export const loginAPI = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/user/login`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};
// 找回密码
export const findpwdAPI = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/user/findpwd`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};

// 发送邮箱验证码
export const sendEmailApi = (data = {}) => {
  return request
    .get(`${HOST_URL}/api/email/send`, { params: data })
    .then((response) => response.data);
};
// 校验邮箱验证码
export const verifyEmailApi = (data = {}) => {
  return request
    .get(`${HOST_URL}/api/email/verify`, { params: data })
    .then((response) => response.data);
};
// 删除邮箱验证码
export const removeEmailApi = (data = {}) => {
  return request
    .get(`${HOST_URL}/api/email/remove`, { params: data })
    .then((response) => response.data);
};

// 删除图片
export const removePhotoApi = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/photo/remove`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};

// 发布轮播图
export const addBannerApi = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/banner/add`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};

// 获取轮播图列表
export const bannerListApi = (data = {}) => {
  return request
    .get(`${HOST_URL}/api/banner/lists`, { params: data })
    .then((response) => response.data);
};

// 删除轮播图记录
export const removeBannerApi = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/banner/remove`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};

// 上传图片（本地预览，点击发布才调用）
export const imagePreviewApi = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/photo/preview`, data, {
      headers: { "Content-Type": "multipart/form-data" },
    })
    .then((response) => response.data);
};

// 获取用户信息
export const getUserInfoApi = (data = {}) => {
  return request
    .post(`${HOST_URL}/api/user/info`, data, {
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
    })
    .then((response) => response.data);
};

export const fetchData = () => {
  return request({
    url: "./mock/table.json",
    method: "get",
  });
};

export const fetchUserData = () => {
  return request({
    url: "./mock/user.json",
    method: "get",
  });
};

export const fetchRoleData = () => {
  return request({
    url: "./mock/role.json",
    method: "get",
  });
};
